<%@ page contentType = "text/html;charset=UTF-8" language="java"
    import="java.util.ArrayList,
             java.util.Iterator,
             java.util.LinkedHashMap,
             java.util.Set,
             com.scalar.chiptrack.operations.LotView,
             com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);
%>

<chiptrack:checkLogon sourcePage="/lotTrace.do"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML><HEAD><TITLE>ScalarSoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type='text/css' rel='stylesheet'>
</HEAD>
<BODY bgColor='#ffffff' leftMargin="0" topMargin='0' marginheight='0' marginwidth='0'>

<script language="javascript">

    function getLotDetails( lotId, psType )
    {   
        newWindow = window.open('<%=chipTracContext%>/lotTrace.do?lotId=' + lotId +'&PsType=' + psType,'LotHistory','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=300,left=100,top=50,resizable=yes');
        newWindow.moveTo( 100, 50 );
        newWindow.focus();
    }
</script>
<!-- Top Header Start-->
<%@include file="/jsp/includes/header.jsp"  %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@include file="/jsp/operations/operations_menu.jsp" %>
            <!-- end of the side navigations -->
        </TD>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%" >
            <img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>
            <BR>
            <!-- from here your body starts -->
            <%
                String lotNumber = (String)request.getAttribute("lotNumber");
                String lotType   = (String)request.getAttribute("lotType");                
                LinkedHashMap map = (LinkedHashMap)request.getAttribute("traceMap");
            %>
    		<p align="center" class="NArialW"><%= lotNumber %> Trace</p>

            <P class=NArialS><img border="0" src="<%=chipTracContext%>/jsp/includes/images/exclamation-46x47.gif" width="24" height="24" align='center'> Lots are in <font color = 'red'><b>Red:</b></font> Hold <font color = 'Blue'><b>Blue:</b></font> Active
                <font color = 'gray'><b>Gray:</b></font> Scrap <font color= 'orange'> <b>Orange:</b></font> Split
             </P>

            <table border="0" width="100%" align=right>
                
                <tr>
                <%
                    Set keys = map.keySet();
                    int size = keys.size();
                    int index = 0;
                    Iterator key_it = keys.iterator();
                    Object key = null;
                    while( key_it.hasNext() )
                    {
                %>
                        <td nowrap bgcolor="#ffffcc" valign=top>
                <%
                        key = key_it.next();
                        String k = ( String ) key;
                        ArrayList list = ( ArrayList ) map.get( key );
                        Iterator it = list.iterator();

                        while( it.hasNext() )
                        {
                            LotView lview = ( LotView ) it.next();
                        %>
                                    <% if(!"ship".equalsIgnoreCase(k)){ %>
                                    <font class=NArialL> <%= lview.getCurrentProcess()%> </font>
                                     <% if ( "Hold".equalsIgnoreCase( lview.getLotStatus() ) )  { %>
                                      <font color = 'red'>

                                     <%}else if ( "Moved To Scrap".equalsIgnoreCase( lview.getLotComments() ) )  { %>
                                      <font color = 'gray' >

                                    <% } else if ( "Running".equalsIgnoreCase( lview.getLotStatus() ) )  { %>
                                      <font color = 'blue'>
                                    <% } else if ( lview.getSplitFlag() == 0 )  { %>
                                      <font color = 'orange'>
                                    <% } else{ %>
                                    </font>
                                    <% } %>
                                    <% if ( lotType.equalsIgnoreCase("fabLot") == false ) { %>
                                    <BR><BR><font class=NArialS><b>Lot #:</b> <a href="javascript:getLotDetails(<%= lview.getLotID() %>, '<%= lview.getProcessTypeName()%>')" <%--onmouseover="window.status='Click to Lot History';return true" onmouseout="window.status='';return true"--%>><%= lview.getLotNumber()%></a></font>
                                    <BR><font class=NArialS>Fab Lot No: <%= lview.getFabLotNumber()%></font>
                                    <%  } else { %>
                                    <BR><BR><font class=NArialS><b>Fab Lot #:</b> <%= lview.getFabLotNumber()%></font>
                                    <%   } %>
                                    <BR><font class=NArialS>Part #: <%= lview.getPartNumber()%></font>
                                    <BR><font class=NArialS>Vendor Name: <%= lview.getVendorLocationName()%></font>
                                    <BR><font class=NArialS>Qty In: <%= lview.getQuantityIn()%></font>
                                    <BR><font class=NArialS>Qty Out: <%= lview.getQuantityOut()%></font>
                                    <BR><font class=NArialS>Date In#: <%= lview.getDateIn()%></font>
                                    <BR><font class=NArialS>Date Out#: <%= lview.getDateOut()%></font>
                                    <BR><font class=NArialS>Category: <%= lview.getLotCategory()%></font>    
                                    <BR><font class=NArialS>ShipTo: <%= lview.getShipToVendorName()%></font>
                                    <BR><font class=NArialS>DateCode: <%= lview.getDateCode()%></font>
                                    
                                    <% if ("CP".equalsIgnoreCase( lview.getCurrentProcess() ) || "SORT".equalsIgnoreCase( lview.getCurrentProcess() ) || "FT".equalsIgnoreCase( lview.getCurrentProcess() ) || "TEST".equalsIgnoreCase( lview.getCurrentProcess() ) ) { %>
                                        <BR><font class=NArialS>TestPgm: <%= lview.getTestProgram()%></font>
                                        <BR><font class=NArialS>Good Die: <%= lview.getGoodDie()%></font>
                                    <% } %>
                                    <% if ("Assembly".equalsIgnoreCase( lview.getCurrentProcess() )  ) { %>
                                        <BR><font class=NArialS><B><bean:message key="label.operation.release.assm.BOMLot"/>Lot No's:  <%= lview.getBomLotNo()%></B></font>
                                        <BR><font class=NArialS><B><bean:message key="label.operation.release.assm.BOMLot"/> Qty's: <%= lview.getBomLotQty()%></B></font>
                                    <% } %>
                                    <BR><font class=NArialS>Lot Comments: <b><%= lview.getLotComments()%></b></font>
                                     <% if ( "Hold".equalsIgnoreCase( lview.getLotStatus() ) )  { %>
                                       <BR><font class=NArialS><%= lview.getHoldReason() %> </font></font>
                                    <% } %>
                                     </font>
                                 <%
                                 }
                                 else
                                 {
                                 %>
                                  <font class=NArialL><%= k.toUpperCase()%></font>
                                  <% if ( lotType.equalsIgnoreCase("fabLot") ) { %>
                                    <BR><BR><font class=NArialS><b>Fab Lot #:</b> <%= lview.getFabLotNumber()%></font>
                                 <%  } else { %>
                                    <BR><BR><font class=NArialS><b>Lot #:</b> <%= lview.getLotNumber()%> </font>
                                    <%   } %>
                                 <%--<BR><BR><font class=NArialS><b>Lot #:</b> <%= lview.getLotNumber()%> </font>--%>
                                 <BR><font class=NArialS><b>SO#:</b> <%= lview.getSalesOrderNumber()%></font>
                                 <BR><font class=NArialS>Customer #: <%= lview.getCustomerName()%></font>
                                 <BR><font class=NArialS>Ship Qty: <%= lview.getShipQty()%></font>
                                 <BR><font class=NArialS>Actual Ship Date: <%= lview.getActualShipDate()%></font>

                                <%
                                 }
                                if ( it.hasNext())
                                {
                                    out.print("<table width='100%' bgcolor='black' ><tr><td></td></tr></table>");
                                }
                                else
                                {
                                    out.print("<BR>");
                                }
       						}
       						%>
                            <BR>
       						</td>
       						<td>
                                <% if(index < ( size - 1 ) )
                                {
                                %>
                                    <IMG alt= "" src="<%=chipTracContext%>/jsp/includes/images/rightarrow.gif" width=38 height=14 border=0>
                                <% } %>
                            </td>
                <%
                        index++;
                    }
                %>
                </tr>
                <tr>
                    <TD bgcolor="#ffffff"><IMG alt="" height= 25 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width= 100></TD>
                </tr>
                <tr align="center">
                    <td colspan="<%=size*2%>">
                        <a href="javascript:history.back();">
                            <img alt ="" border="0" src="<%=chipTracContext%>/jsp/includes/images/back.gif"  onmouseover="window.status='Click to go back';return true" onmouseout="window.status='';return true" title="Click here to go back"  width="45" height="15">
                        </a>
                    </td>
                </tr>
             </table>


    <!-- till here -->

    <BR><BR><BR>
    </TD>
    <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
    </TABLE>

    <!-- Footer starts here -->
    <%@include file="/jsp/includes/footer.jsp" %>
    <!-- footer end here -->

</BODY>
</HTML>